package entities;

import menu.Settings;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;

import util.Vector2D;

public class CircleFireEnemy extends Enemy {

	private Weapon weapon;
	private final int phaseTime = 2000;
	private int timer;
	private int phase;
	private Vector2D shotVelocity;

	
	public CircleFireEnemy(float frequency) throws SlickException {
		super("res/enemies/enemy02.png");
		image = image.getScaledCopy(45, 45);
		image.rotate(90f);
		weapon = new SimpleWeapon("res/shot.png", 1, this, (int) (1000f / frequency));
		maxHealth = (int) (12 * Settings.getfactor());
		score = 160;
		shotVelocity = new Vector2D(-300f, 0);
		reset();
	}

	@Override
	public void update(GameContainer gc, int delta) {
		super.update(gc, delta);
		switch (phase) {
		case 1:
			setVelocity(new Vector2D(-120, 0));
			break;
		case 2:
			setVelocity(new Vector2D(0, 0));
			weapon.shoot((shotVelocity = shotVelocity.rotate(10)));
			break;
		default:
			acceleration = new Vector2D(0, timer);
			break;
		}
			timer += delta;
		if (timer > phaseTime) {
			System.out.println("Phase: " + phase);
			phase++;
			timer = 0;
		}
	}

	@Override
	public String getName() {
		return "Circle Fire Enemy";
	}
	
	@Override
	public void reset() {
		super.reset();
		phase = 1;
		setVelocity(new Vector2D(-50 - random.nextInt(50) , 0));
	}

}
